package com.chenyue.cm.api.common;

import com.chenyue.cm.bean.Success;
import com.chenyue.cm.common.domain.JdAboutUs;
import com.chenyue.cm.common.service.CommonInfoService;
import com.chenyue.cm.common.service.JdAboutUsService;
import com.chenyue.cm.match.domain.PublicArea;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author libingxing
 */
@Api(tags = "公共信息展示")
@RestController
@RequestMapping("/api/common")
public class ApiCommonController {

    private final JdAboutUsService aboutUsService;

    private final CommonInfoService commonInfoService;

    public ApiCommonController(JdAboutUsService aboutUsService, CommonInfoService commonInfoService) {
        this.aboutUsService = aboutUsService;
        this.commonInfoService = commonInfoService;
    }

    @GetMapping("/getAbout")
    @ApiOperation("获取关于我们列表")
    @ApiOperationSupport(order = 1)
    @ApiImplicitParams({
            @ApiImplicitParam(value =
                    "获取类型" +
                            "1-关于我们" +
                            "2-隐私政策" +
                            "3-会员权益" +
                            "4-常见问题" +
                            "5-参赛须知" +
                            "6-用户协议" +
                            "7-业务合作" +
                            "8-捷登体育会员协议" +
                            "9-价格说明"+
                            "10-积分规则",
                    name = "type", dataType = "string", required = true)
    })
    public Success<String> getAbout(
            Integer type
    ) {
        final JdAboutUs one = aboutUsService.lambdaQuery().eq(JdAboutUs::getId, type).last(" limit 1").one();
        return Success.success("", one.getContent());
    }

    @GetMapping("/getSecret")
    @ApiOperation("获取关于我们列表")
    @ApiOperationSupport(order = 1)
    @ApiImplicitParams({
            @ApiImplicitParam(value = "获取类型 2-隐私政策", name = "type", dataType = "string", required = true)
    })
    public String getSecret(
            Integer type
    ) {
        final JdAboutUs one = aboutUsService.lambdaQuery().eq(JdAboutUs::getId, type).last(" limit 1").one();
        return one.getContent();
    }

    @GetMapping("/getArea")
    @ApiOperation("获取区域")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "上级id", name = "parentId", dataType = "int", required = true),
    })
    public Success<List<PublicArea>> getArea(
            Integer parentId
    ) {
        List<PublicArea> areaList = commonInfoService.getArea(parentId);
        return Success.success(areaList);
    }

    @GetMapping("/getAreaByLevel")
    @ApiOperation("根据级别获取区域")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "1省2市3县", name = "level", dataType = "int", required = true),
    })
    public Success<List<PublicArea>> getAreaByLevel(
            Integer level
    ) {
        List<PublicArea> areaList = commonInfoService.getAreaByLevel(level);
        return Success.success(areaList);
    }

    @PostMapping("/getPhone")
    @ApiOperation("/客服电话")
    public Success<String> getPhone(
    ) {
        return Success.success("15835985448");
    }

}
